package com.thoughtworks.bytecode2class.constantpool;

import com.thoughtworks.bytecode2class.ClassReader;

public class NameAndTypeConstant extends Constant {

    private int nameIndex;
    private int descriptorIndex;

    public NameAndTypeConstant(ClassReader classReader) {
        super(classReader);
        nameIndex = classReader.forwardChar();
        descriptorIndex = classReader.forwardChar();
    }

    public void description() {
        System.out.printf("[%d]NameAndTypeConstant - [Name:%s, Descriptor:%s]%n",
                getCount(), getName(), getDescriptor());
    }

    public String getName() {
        Utf8Constant constant = (Utf8Constant) classReader.getConstantPool().get(nameIndex);
        return constant.getValue();
    }

    public String getDescriptor() {
        Utf8Constant constant = (Utf8Constant) classReader.getConstantPool().get(descriptorIndex);
        return constant.getValue();
    }
}
